<div class='pagebar'>
<?php
  $bottom = ($page['Limit'] * ($page['Page'] - 1)) + 1;
  $top = $page['Page'] * $page['Limit'];
  if ($top > $page['Max']) { $top = $page['Max']; }

?>
<p>Showing items <?=$bottom;?> to <?=$top;?> of <?=$page['Max'];?></p>
<?php
$links = array();
if ($page['Page'] != 1) {
  $links['|<< First'] = '/products/show/1';
  if ($page['Page'] > 2) {
    $links['< Previous'] = '/products/show/' . ($page['Page'] - 1);
  }
}
$last = ceil($page['Max'] / $page['Limit']);
if ($page['Page'] != $last) {
  if ($page['Page'] < $last - 1) {
    $links['Next >'] = '/products/show/' . ($page['Page'] + 1);
  }
  $links['Last >>|'] = '/products/show/' . $last;
}
echo '<p>';
foreach($links as $title=>$link) {
  echo ' ' . $html->link($title,$link . $args);
}
echo '</p>';
?>
</div>
<?php
$producer = array();
$first = true;
foreach ($products as $product) {
  $item = $product['Product'];
  if ($product['Producer'] != $producer) {
    $producer = $product['Producer'];
    if (!$first) {
      echo '</table>' . "\n";
    }
    $actions = '';
    if ($current_user['auth_type'] == AUTH_PROD and $item['producer_id'] == $current_user['producer_id']) {
      $actions = '<th class="actions"><p>Actions</p></th>';
    }  
    echo '<h3>' . $producer['Member']['business_name'] . '</h3>' . "\n";
    echo "<table>\n <tr><td><p><strong>Product (id#)</strong></p></td><td><p><strong>Category</strong></p><p>Starting Inventory</p></td><td class='price'><p><strong>Price</strong></p><p>Status</p></td>", $actions, "</tr>\n";
    $first = false;
  }
  echo '<tr>' . "\n";
  echo ' <td><p><strong>', $item['product_name'], ' (', $item['product_id'], ')</strong></p></td>', "\n";
  $i = ($item['inventory_on']) ? $item['inventory'] . ' ' . $item['ordering_unit'] . '(s)' : 'unlimited';
  $s = ($item['donotlist']) ? '<em>unlisted</em>' : 'listed';
  $c = (isset($product['Subcategory']['Category'])) ? $product['Subcategory']['Category']['category_name'] .  "::" . $product['Subcategory']['subcategory_name'] : '<em>Uncategorized</em>';
  echo ' <td><p><strong>', $c ,'</strong></p><p>',$i,"</p></td>\n";
  echo ' <td class="price"><p>$ ', number_format($item['unit_price'],2), ' per ' . $item['pricing_unit'], '</p><p>ordered by the ', $item['ordering_unit'], '</p><p>', $s, '</p></td>', "\n";
  if ($current_user['auth_type'] == AUTH_PROD and $item['producer_id'] == $current_user['producer_id']) {
    echo ' <td class="actions">' . "\n";
    echo '  <p>' . $html->link("Edit", '/products/edit/' . $item['product_id'] . '/' . $page['Page']) . '</p>' . "\n";
    echo '  <p>' . $html->link("Delete", '/products/delete/' . $item['product_id']) . '</p>' . "\n";
    echo '</tr>' . "\n";
  }
  
  
}
?>
</table>
<?php
 //pr($products); 
?>
